﻿using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Camera))]
public class CameraFitPixels : MonoBehaviour {

    int height = 0;
    public float maxSize;
    public int zoom;

    exPixelPerfectCamera ex;

	void Start () 
    {
        ex = GetComponent<exPixelPerfectCamera>();
	}

    void Update()
    {
        float fit = ex.orthographicSize / ex.height;
        float size = fit * Screen.height;
        if (zoom < 1)
            zoom = 1;
        while (size / zoom > maxSize)
            zoom++;
        
        int width = Screen.width / zoom;
        int height = Screen.height / zoom;
        camera.pixelRect = new Rect(0, 0, width, height);
        //camera.orthographicSize = size / zoom;
    }
}
